## BTW

rm(list = ls())

library(tidyverse)

## Load Data

btw <- readRDS("data/treat_to_n.rds") %>%
  mutate(decrease = ifelse(str_detect(
    treat_categorical4,
    "Decrease"
  ), 1, 0)) %>%
  group_by(year) %>%
  summarise(n_exits = sum(decrease)) %>%
  filter(year != 2013) %>%
  mutate(year = as.character(year)) %>%
  ungroup()

## Number of counties 

n_counties <- readRDS('data/treat_to_n.rds') %>%
  group_by(year) %>% 
  summarise(nobs = n()) %>%
  mutate(year = as.character(year))

## Recode period

btw <- btw %>%
  mutate(period = recode(year, 
                         '1983' = '1980 - 1983',
                         '1987' = '1983 - 1987',
                         '1990' = '1987 - 1990',
                         '1994' = '1990 - 1994',
                         '1998' = '1994 - 1998',
                         '2005' = '2002 - 2005',
                         '2009' = '2005 - 2009'))

## Get share of exits

btw <- btw %>%
  left_join(n_counties) %>%
  mutate(share_exits = n_exits / nobs)

## Figure A3

p1 <- ggplot(btw, aes(x = as.character(period), y = share_exits)) +
  geom_bar(
    stat = "identity", width = .8,
    color = "black", fill = "grey93"
  ) +
  theme_bw() +
  labs(
    y = "Share of counties\nwith newspaper exit",
    x = ""
  ) +
  theme(axis.text.x = element_text(
    angle = 45,
    vjust = 1, 
    hjust = 1
  ))

p1
